<template>
	<view>
		<!-- 已收藏 -->
		<view class="collect">
			<view class="item" v-for="(item, index) in clist"  @click="go('/pages/info/detail?id=' + item.info_id)">
				<u--image :showLoading="true" :src="item.info.img" width="200rpx" height="150rpx"></u--image>
				<view class="info">
					<view class="title">
						<u--text :lines="2" :text="item.info.title"></u--text>
					</view>
					<view class="price">
						<text class="price-num">{{item.info.price}}</text>
						<text class="unit">{{item.info.unit}}</text>
					</view>
				</view>
			</view>
		</view>
		<!-- 未收藏 -->
		<view class="uncollect">
			<u-list @scrolltolower="scrolltolower">
				<u-list-item v-for="(item, index) in list" >
					<view class="item"  @click="go('/pages/info/detail?id=' + item.info_id)">
						<u--image :showLoading="true" :src="item.img" width="200rpx" height="150rpx"></u--image>
						<view class="info">
							<view class="title">
								<u--text :lines="2" :text="item.title"></u--text>
							</view>
							<view class="price">
								<text class="price-num">{{item.price}}</text>
								<text class="unit">{{item.unit}}</text>
							</view>
						</view>
					</view>
				</u-list-item>
			</u-list>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				clist:[],
				info:{},
				list: [],
				is_more: 0,
				query: {
					page: 1,
					size: 10
				},
			};
		},
		onLoad(e) {
			if(!uni.getStorageSync('LOGIN_TOKEN_KEY')){
				uni.navigateTo({
					url: "/pages/login/login"
				});
				return;
			}
			this.getCollectList();
			setTimeout(()=>{
				this.getPageFun();
			},300)
		},
		methods: {
			go(url){
				uni.navigateTo({
					url
				})
			},
			scrolltolower(){
				if (this.is_more) {
					this.getPageFun();
				}
			},
			getCollectList(){
				var _this = this;
				uni.$u.http.post('/User/likePage',{page:1,size:40}).then(async res =>{
					this.clist = res.lists;
				}).catch(err => {
				})
			},
			getPageFun() {
				var _this = this;
				uni.$u.http.post('/Info/cpage',{...this.query}).then(async res =>{
					let curPageData = res.lists;
					if (this.query.page == 1) {
						_this.list = [];
					}
					if (res.is_more) {
						_this.query.page++;
					}
					_this.is_more = res.is_more;
					_this.list = _this.list.concat(curPageData);
				}).catch(err => {
				})
			},
		}
	}
</script>

<style lang="scss" scoped>

</style>
